package com.tzy.for10evalue.controller;

import com.tzy.for10evalue.haoyong.excelexport.sysbackservice.impl.ProductUnitImportServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.util.List;

/**
 * 导入流程：
 * 1.ProductUnitImportServiceImpl 导入服务sysback发起 设置不重复的导入类型ImportType
 *   发送消息时设置topic里不重复的消费类型 sendWithoutTransactionMsg的CommonImportDetailDTO的type
 * 至此发送端结束 以后的每种导入只需要添加不同的ProductUnitImportServiceImpl的业务service即可
 *
 * 2.根据ServiceFactory.getProductBatchImportNewHandler方法从topic的type获取具体导入的业务service
 * @author tzy
 * @date 2022/11/16 15:50
 */
@RestController
public class HaoyongExcelexportController {
    @Autowired
    @Qualifier("productUnitImportService")
    private ProductUnitImportServiceImpl productUnitImportService;

    @RequestMapping(value = "importUnitExcel", method = RequestMethod.POST)
    public RetFrontModel importUnitExcel(MultipartFile excel) {
        String excelName = ((CommonsMultipartFile) excel).getFileItem().getName();
        List<ProductUnitExcelDTO> productUnitExcelDTOs = NewExcelUtil.OnceRead(excel, ProductUnitExcelDTO.class);
        productUnitImportService.productSkuImport(excelName, productUnitExcelDTOs, SysLoginUserHelper.getApiParamDTO());
        return RetFrontDTOHelper.getSuccessRetFrontModel(null);
    }
}
